1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module gtk.FileFilter; 26 27 private import glib.ConstructionException; 28 private import glib.Str; 29 private import glib.Variant; 30 private import glib.c.functions; 31 private import gobject.ObjectG; 32 private import gtk.BuildableIF; 33 private import gtk.BuildableT; 34 private import gtk.Filter; 35 private import gtk.c.functions; 36 public import gtk.c.types; 37 38 39 /** 40 * `GtkFileFilter` filters files by name or mime type. 41 * 42 * `GtkFileFilter` can be used to restrict the files being shown in a 43 * `GtkFileChooser`. Files can be filtered based on their name (with 44 * [method@Gtk.FileFilter.add_pattern] or [method@Gtk.FileFilter.add_suffix]) 45 * or on their mime type (with [method@Gtk.FileFilter.add_mime_type]). 46 * 47 * Filtering by mime types handles aliasing and subclassing of mime 48 * types; e.g. a filter for text/plain also matches a file with mime 49 * type application/rtf, since application/rtf is a subclass of 50 * text/plain. Note that `GtkFileFilter` allows wildcards for the 51 * subtype of a mime type, so you can e.g. filter for image/\*. 52 * 53 * Normally, file filters are used by adding them to a `GtkFileChooser` 54 * (see [method@Gtk.FileChooser.add_filter]), but it is also possible to 55 * manually use a file filter on any [class@Gtk.FilterListModel] containing 56 * `GFileInfo` objects. 57 * 58 * # GtkFileFilter as GtkBuildable 59 * 60 * The `GtkFileFilter` implementation of the `GtkBuildable` interface 61 * supports adding rules using the `<mime-types>` and `<patterns>` and 62 * `<suffixes>` elements and listing the rules within. Specifying a 63 * `<mime-type>` or `<pattern>` or `<suffix>` has the same effect as 64 * as calling 65 * [method@Gtk.FileFilter.add_mime_type] or 66 * [method@Gtk.FileFilter.add_pattern] or 67 * [method@Gtk.FileFilter.add_suffix]. 68 * 69 * An example of a UI definition fragment specifying `GtkFileFilter` 70 * rules: 71 * ```xml 72 * <object class="GtkFileFilter"> 73 * <property name="name" translatable="yes">Text and Images</property> 74 * <mime-types> 75 * <mime-type>text/plain</mime-type> 76 * <mime-type>image/ *</mime-type> 77 * </mime-types> 78 * <patterns> 79 * <pattern>*.txt</pattern> 80 * </patterns> 81 * <suffixes> 82 * <suffix>png</suffix> 83 * </suffixes> 84 * </object> 85 * ``` 86 */ 87 public class FileFilter : Filter, BuildableIF 88 { 89 /** the main Gtk struct */ 90 protected GtkFileFilter* gtkFileFilter; 91 92 /** Get the main Gtk struct */ 93 public GtkFileFilter* getFileFilterStruct(bool transferOwnership = false) 94 { 95 if (transferOwnership) 96 ownedRef = false; 97 return gtkFileFilter; 98 } 99 100 /** the main Gtk struct as a void* */ 101 protected override void* getStruct() 102 { 103 return cast(void*)gtkFileFilter; 104 } 105 106 /** 107 * Sets our main struct and passes it to the parent class. 108 */ 109 public this (GtkFileFilter* gtkFileFilter, bool ownedRef = false) 110 { 111 this.gtkFileFilter = gtkFileFilter; 112 super(cast(GtkFilter*)gtkFileFilter, ownedRef); 113 } 114 115 // add the Buildable capabilities 116 mixin BuildableT!(GtkFileFilter); 117 118 119 /** */ 120 public static GType getType() 121 { 122 return gtk_file_filter_get_type(); 123 } 124 125 /** 126 * Creates a new `GtkFileFilter` with no rules added to it. 127 * 128 * Such a filter doesn’t accept any files, so is not 129 * particularly useful until you add rules with 130 * [method@Gtk.FileFilter.add_mime_type], 131 * [method@Gtk.FileFilter.add_pattern], 132 * [method@Gtk.FileFilter.add_suffix] or 133 * [method@Gtk.FileFilter.add_pixbuf_formats]. 134 * 135 * To create a filter that accepts any file, use: 136 * ```c 137 * GtkFileFilter *filter = gtk_file_filter_new (); 138 * gtk_file_filter_add_pattern (filter, "*"); 139 * ``` 140 * 141 * Returns: a new `GtkFileFilter` 142 * 143 * Throws: ConstructionException GTK+ fails to create the object. 144 */ 145 public this() 146 { 147 auto __p = gtk_file_filter_new(); 148 149 if(__p is null) 150 { 151 throw new ConstructionException("null returned by new"); 152 } 153 154 this(cast(GtkFileFilter*) __p, true); 155 } 156 157 /** 158 * Deserialize a file filter from a `GVariant`. 159 * 160 * The variant must be in the format produced by 161 * [method@Gtk.FileFilter.to_gvariant]. 162 * 163 * Params: 164 * variant = an `a{sv}` `GVariant` 165 * 166 * Returns: a new `GtkFileFilter` object 167 * 168 * Throws: ConstructionException GTK+ fails to create the object. 169 */ 170 public this(Variant variant) 171 { 172 auto __p = gtk_file_filter_new_from_gvariant((variant is null) ? null : variant.getVariantStruct()); 173 174 if(__p is null) 175 { 176 throw new ConstructionException("null returned by new_from_gvariant"); 177 } 178 179 this(cast(GtkFileFilter*) __p, true); 180 } 181 182 /** 183 * Adds a rule allowing a given mime type to @filter. 184 * 185 * Params: 186 * mimeType = name of a MIME type 187 */ 188 public void addMimeType(string mimeType) 189 { 190 gtk_file_filter_add_mime_type(gtkFileFilter, Str.toStringz(mimeType)); 191 } 192 193 /** 194 * Adds a rule allowing a shell style glob to a filter. 195 * 196 * Note that it depends on the platform whether pattern 197 * matching ignores case or not. On Windows, it does, on 198 * other platforms, it doesn't. 199 * 200 * Params: 201 * pattern = a shell style glob 202 */ 203 public void addPattern(string pattern) 204 { 205 gtk_file_filter_add_pattern(gtkFileFilter, Str.toStringz(pattern)); 206 } 207 208 /** 209 * Adds a rule allowing image files in the formats supported 210 * by GdkPixbuf. 211 * 212 * This is equivalent to calling [method@Gtk.FileFilter.add_mime_type] 213 * for all the supported mime types. 214 */ 215 public void addPixbufFormats() 216 { 217 gtk_file_filter_add_pixbuf_formats(gtkFileFilter); 218 } 219 220 /** 221 * Adds a suffix match rule to a filter. 222 * 223 * This is similar to adding a match for the pattern 224 * "*.@suffix". 225 * 226 * In contrast to pattern matches, suffix matches 227 * are *always* case-insensitive. 228 * 229 * Params: 230 * suffix = filename suffix to match 231 * 232 * Since: 4.4 233 */ 234 public void addSuffix(string suffix) 235 { 236 gtk_file_filter_add_suffix(gtkFileFilter, Str.toStringz(suffix)); 237 } 238 239 /** 240 * Gets the attributes that need to be filled in for the `GFileInfo` 241 * passed to this filter. 242 * 243 * This function will not typically be used by applications; 244 * it is intended principally for use in the implementation 245 * of `GtkFileChooser`. 246 * 247 * Returns: the attributes 248 */ 249 public string[] getAttributes() 250 { 251 return Str.toStringArray(gtk_file_filter_get_attributes(gtkFileFilter)); 252 } 253 254 /** 255 * Gets the human-readable name for the filter. 256 * 257 * See [method@Gtk.FileFilter.set_name]. 258 * 259 * Returns: The human-readable name of the filter 260 */ 261 public string getName() 262 { 263 return Str.toString(gtk_file_filter_get_name(gtkFileFilter)); 264 } 265 266 /** 267 * Sets a human-readable name of the filter. 268 * 269 * This is the string that will be displayed in the file chooser 270 * if there is a selectable list of filters. 271 * 272 * Params: 273 * name = the human-readable-name for the filter, or %NULL 274 * to remove any existing name. 275 */ 276 public void setName(string name) 277 { 278 gtk_file_filter_set_name(gtkFileFilter, Str.toStringz(name)); 279 } 280 281 /** 282 * Serialize a file filter to an `a{sv}` variant. 283 * 284 * Returns: a new, floating, `GVariant` 285 */ 286 public Variant toGvariant() 287 { 288 auto __p = gtk_file_filter_to_gvariant(gtkFileFilter); 289 290 if(__p is null) 291 { 292 return null; 293 } 294 295 return new Variant(cast(GVariant*) __p); 296 } 297 }